package com.yc.tomcat.impl;

import com.yc.tomcat.HttpServletRequest;
import com.yc.tomcat.HttpServletResponse;
import com.yc.tomcat.HttpSession;
import com.yc.tomcat.ServletException;

import java.io.IOException;
import java.io.PrintWriter;

public class InvalidateServlet extends HttpServletImpl{
    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        // 获取当前的HttpSession对象
        HttpSession session = request.getSession();

        if (session != null) {
            // 使当前Session失效
            System.out.println(session.getId());
            session.invalidate();
            System.out.println(session.getId());
            PrintWriter out=response.getWriter();
            response.setContentType("text/html;charset=utf-8");
            out.println("失效了吗？");
        }
        if(session==null){
    // 跳转到登录页面或其他页面
    response.sendRedirect("from.html");
}

    }
}
